package net.alpcontrol.bi.task;

import net.alpcontrol.bi.bootstrap.utils.SpringContextUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;

/**
 * @ClassName: TaskJobConfiguration
 * @Description: 定时任务配置类
 * @author congqing
 * @date 2020-08-28
 */
@Configuration
@EnableScheduling
public class TaskJobConfiguration implements SchedulingConfigurer {
    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {

    }


//    /**
//     * LED双色屏配置
//     */
//    @Autowired
//    private LEDBiColorConfig ledBiColorConfig;
//
//    /**
//     * LED全彩屏配置
//     */
//    @Autowired
//    private LEDFullColorConfig ledFullColorConfig;
//
//    @Override
//    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
//        // 开启多线程支持
//        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
//        taskScheduler.setPoolSize(10);
//        taskScheduler.initialize();
//        taskRegistrar.setTaskScheduler(taskScheduler);
//
//        // LED双色屏推送
//        if(ledBiColorConfig.getEnable() && StringUtils.isNotEmpty(ledBiColorConfig.getCron())){
//            taskRegistrar.addTriggerTask(SpringContextUtil.getBean(ILEDBiColorService.class),
//                    triggerContext -> {
//                        String cron = ledBiColorConfig.getCron();
//                        return new CronTrigger(cron).nextExecutionTime(triggerContext);
//                    }
//            );
//        }
//
//        // LED全彩屏推送
//        if(ledFullColorConfig.getEnable() && StringUtils.isNotEmpty(ledFullColorConfig.getCron())){
//            taskRegistrar.addTriggerTask(SpringContextUtil.getBean(ILEDFullColorService.class),
//                    triggerContext -> {
//                        String cron = ledFullColorConfig.getCron();
//                        return new CronTrigger(cron).nextExecutionTime(triggerContext);
//                    }
//            );
//        }
//
//    }

}

